package com.kaishengit.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.kaishengit.pojo.Goal;
import com.kaishengit.pojo.Task;
import com.kaishengit.pojo.User;

@Repository
public class TaskDao extends BaseDao<Task, String>{

	public List<Task> findAllTask(Goal goal) {
		String hql="from Task where goal=:goal order by createtime desc";
		Query query=getSession().createQuery(hql);
		query.setParameter("goal", goal);
		@SuppressWarnings("unchecked")
		List<Task> taskList=query.list();
		return taskList;
	}

	public void update(Task task) {
		getSession().update(task);
	}

	public List<Task> findTaskByUser(User user) {
		String hql="from Task where user=:user order by createtime desc";
		Query query=getSession().createQuery(hql);
		query.setParameter("user", user);
		@SuppressWarnings("unchecked")
		List<Task> taskList=query.list();
		return taskList;
		
	}
}
